home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2473 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: crchh327.rich.bnr.ca!karlon
  2. From: karlon@bnr.ca (Karlon West)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with ascii to number conversion.
  5. Date: 21 Jan 1996 19:43:45 GMT
  6. Organization: Bell-Northern Research, Richardson, TX
  7. Distribution: world
  8. Message-ID: <4du51h$dc0@crchh327.rich.bnr.ca>
  9. References: <96012012081730705@busilink.com> <20JAN199609563071@erich.triumf.ca>
  10. NNTP-Posting-Host: crchhdaa.rich.bnr.ca
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. P.Bennett (bennett@erich.triumf.ca) wrote:
  14. > In article <96012012081730705@busilink.com>, paul.kelley@busilink.com (Paul Kelley) writes...
  15. > >Hi,
  16. > > i am a beginner c programmer, stuck on what i thought was a simple
  17. > >problem. I have an ascii input file that contains payroll info for a
  18. > >month, the data is monetary values as ascii strings. I am trying to
  19. > >convert the ascii ti numbers total the result then place in another
  20. > >file. I am using micrsoft quick C and the ascii to number functions in
  21. > >it. Apparenntly these functions only work correctly up to four digits.
  22. > >After that teh ouput goes wild.
  23.  
  24. > A widely used commercial product like Micro$oft, unlikely to have this sort of
  25. > a bug, so it is probably your program.  The problem would be easier to resolve
  26. > if you had showed some source code.
  27.  
  28. > However, "4 digits" sounds suspiciously like the size of a pointer in some
  29. > memory models...
  30.  
  31. I'd guess that he's hitting the 16 bit bounds on IBM's ints. It works
  32. great from 0 up to 9999, but with five or more digits, you start wrapping
  33. at 32767. So, Paul, instead of using atoi(), use strtol().
  34.